/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.droidlover.xrecyclerview.demo;

import cn.droidlover.xrecyclerview.XRecyclerContentLayout;
import cn.droidlover.xrecyclerview.demo.slice.EmptyComponent;
import cn.droidlover.xrecyclerview.demo.slice.ErrorComponent;
import cn.droidlover.xrecyclerview.demo.slice.LoadingComponent;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.agp.components.Component;
import ohos.agp.components.DependentLayout;
import ohos.agp.components.ListContainer;
import org.junit.BeforeClass;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
/**
 * 测试
 *
 * @author wz
 * @since 2021-04-08
 */
public class ExampleOhosTest {
    static XRecyclerContentLayout xRecyclerContentLayout;

    @Test
    public void testBundleName() {
        final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName();
        assertEquals("cn.droidlover.xrecyclerview.demo", actualBundleName);
    }

    @BeforeClass
    public static void set() {
        Ability ability = AbilityDelegatorRegistry.getAbilityDelegator().getCurrentTopAbility();
        xRecyclerContentLayout = new XRecyclerContentLayout(ability.getContext());
        xRecyclerContentLayout.addEmptyView(new EmptyComponent(ability.getContext()));
        xRecyclerContentLayout.addErrorView(new ErrorComponent(ability.getContext()));
        xRecyclerContentLayout.addLoadingView(new LoadingComponent(ability.getContext()));
        xRecyclerContentLayout.addContentView(new ListContainer(ability.getContext()));

    }

    @Test
    public void testEmptyView() {
        DependentLayout dependentLayout = xRecyclerContentLayout.getEmptyView();
        Component component = dependentLayout.getComponentAt(0);
        Class sls = component.getClass();
        String str=sls.getName();
        System.out.println(str);
        assertEquals("cn.droidlover.xrecyclerview.demo.slice.EmptyComponent", sls.getName());
    }
    @Test
    public void testErrorView() {
        DependentLayout dependentLayout = xRecyclerContentLayout.getErrorView();
        Component component = dependentLayout.getComponentAt(0);
        Class sls = component.getClass();
        String str=sls.getName();
        System.out.println(str);
        assertEquals("cn.droidlover.xrecyclerview.demo.slice.ErrorComponent", sls.getName());
    }

    @Test
    public void testLoadingView() {
        DependentLayout dependentLayout = xRecyclerContentLayout.getLoadingView();
        Component component = dependentLayout.getComponentAt(0);
        Class sls = component.getClass();
        String str=sls.getName();
        System.out.println(str);
        assertEquals("cn.droidlover.xrecyclerview.demo.slice.LoadingComponent", sls.getName());
    }
    @Test
    public void testContentView() {
        DependentLayout dependentLayout = xRecyclerContentLayout.getContentView();
        Component component = dependentLayout.getComponentAt(0);
        Class sls = component.getClass();
        String str=sls.getName();
        System.out.println(str);
        assertEquals("ohos.agp.components.ListContainer", sls.getName());
    }
}